package com.zhenhunfan.bootserver.service;

import com.zhenhunfan.HelloProto;
import com.zhenhunfan.HelloServiceGrpc;
import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author zhanghong
 * @date 2023/7/18
 */
@GrpcService
public class HelloServiceImpl extends HelloServiceGrpc.HelloServiceImplBase {
    @Override
    public void hello(HelloProto.HelloRequest request, StreamObserver<HelloProto.HelloResponse> responseObserver) {
        //----------1.接受客户端的请求参数----------
        String name = request.getName();
        //----------2.业务处理----------
        System.out.println("name 参数值：" + name);

        //----------3.封装响应----------
        //-----3.1 创建响应对象的构建者-----
        HelloProto.HelloResponse.Builder builder = HelloProto.HelloResponse.newBuilder();
        //-----3.2 填充数据-----
        builder.setResult("这只使用net.devh的结果：" + name + "：嘿嘿!");
        //-----3.3 封装响应对象-----
        HelloProto.HelloResponse helloResponse = builder.build();

        responseObserver.onNext(helloResponse);
        responseObserver.onCompleted();
    }
}
